// pages/mine/collect/components/qiye/qiye.js
const { imgUrl } = getApp().globalData;
import { mineApi } from "@/utils/request/api/mine";
Component({

  /**
   * 组件的属性列表
   */
  properties: {
    id: {
      type: Number,
      value: 0
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    imgUrl: imgUrl + "mine/",
    refresherStatus: false,
    hasMore: true,
    page: 1,
    page_size: 10,
    total: 0,
    list: [],
    announcement_types: ['调研公告','采购公告','澄清公告','中标公告']
  },
  attached() {
    this.getList();
},

  /**
   * 组件的方法列表
   */
  methods: {
    // 上下拉加载
    // 触底
    scrolltolower() {
      if (!this.data.hasMore) {
        return;
      }
      let page = this.data.page + 1;
      this.setData({
        page,
      });
      this.getList();
    },
    // 下拉刷新
    handleRefresherRefresh() {
      this.setData({
        refresherStatus: true,
        page: 1,
        hasMore: true,
      });
      this.getList();
    },
    getList() {
      mineApi
        .collectCompanyList({
          collect_folder_id: this.data.id,
          page: this.data.page,
          page_size: this.data.page_size,
        })
        .then((res) => {
          let arr = res.data.list;
          arr.map(item => {
            let date = new Date(item.created_at);
            item.created_at = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()

            date = new Date(item.updated_at);
            item.updated_at = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();

            return item;
          })
          this.setData({
            list: this.data.page == 1 ? arr : this.data.list.concat(arr),
            total: res.data.total,
            refresherStatus: false,
            hasMore: this.data.page * this.data.page_size <= res.data.total,
          });
        });
    },
  }
})